package com.desaysv.wandroid.projection;

import android.content.Intent;
import android.media.projection.MediaProjection;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.desaysv.wandroid.utils.ProjectManager;
import com.desaysv.wandroid.utils.ProjectionService;

public class ProjectionActivity extends AppCompatActivity {

    private static final String TAG = "[ProjectionActivity]";
    private final static int REQUEST_CODE = 10001;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent captureIntent = ProjectionService.getInstance().getProjectionManager().createScreenCaptureIntent();
        startActivityForResult(captureIntent, REQUEST_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
            MediaProjection mMediaProject = ProjectionService.getInstance().getProjectionManager().getMediaProjection(resultCode, data);
            ProjectionService.getInstance().setmMediaProject(mMediaProject);
            finish();
//            ProjectManager.getInstance().initRecord(ProjectionActivity.this, resultCode, data, new ProjectManager.RecordCallBack() {
//                @Override
//                public void recordingData(byte[] data) {
//                    //录制的数据
//                }
//
//                @Override
//                public void error(Throwable e) {
//
//                }
//            });
//            ProjectManager.getInstance().startRecord(720, 1080, 30, 30);
        }
    }
}
